package com.wan37.auth.service.impl;

import com.wan37.auth.dao.UserDao;
import com.wan37.auth.dao.impl.UserDaoImpl;
import com.wan37.auth.domain.User;
import com.wan37.auth.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : luoyong
 * @date : 2020-05-27 17:04
 **/
@Service("registerService")
public class RegisterServiceImpl implements RegisterService {

    @Autowired
    private UserDao userDao;

    @Override
    public synchronized boolean registerUser(User user) {
        if (exist((user))) {
            return false;
        }

        return userDao.add(user);
    }

    @Override
    public boolean exist(User user) {

        User user1 = userDao.getUserByUserId(user.getUserId());
        if (user1 == null) {
            return false;
        }
        return true;
    }
}
